<div id="wrapper">
	<!--左侧导航开始-->
	<?=\app\widgets\MenuWidget::widget();?>
	<!--左侧导航结束-->
	<!--右侧部分开始-->
	<div id="page-wrapper" class="gray-bg dashbard-1">
		<?=$this->render('@app/modules/admin/views/layouts/inc_naver');?>
		<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>用户组 <small>权限分配</small></h5>
					</div>
					<div class="ibox-content">
						<form method="post" class="form-horizontal" action="create">
							<div class="form-group">
								<label class="col-sm-2 control-label require">管理组名称</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" name="groupName" value="<?php echo $groupName;?>" required="" aria-required="true"> <span class="help-block m-b-none">名称不能为空</span>
									<input type="hidden" class="form-control" name="groupId" value="<?php echo $groupId;?>">
									<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken; ?>">
								</div>
							</div>
							<?php foreach (\app\constants\Acl::$aclConfig as $k => $v): ?>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label"><input type="checkbox" name="acl[]" value="<?=$v['acl'];?>" class="levelFirst" id="inlineCheckbox"  <?php if (in_array($v['acl'], $groupAcl)):?>checked="checked"<?php endif;?>><?=$k;?></label>
								<div class="col-sm-10">
									<?php foreach ($v['action'] as $kk => $vv): ?>
									<div class="levelSecond">
									<label class="col-sm-4 checkbox-inline"><input type="checkbox" name="acl[]" value="<?=$vv['acl'];?>" class="secMenu" id="inlineCheckbox" <?php if (in_array($vv['acl'], $groupAcl)):?>checked="checked"<?php endif;?>><?=$vv['name'];?></label>
									<div class="form-group">
										<div class="col-sm-7">
									<?php foreach ($vv['list_acl'] as $kkk => $vvv): ?>
											<label class="checkbox-inline">
												<input type="checkbox" value="<?=$vvv;?>" name="acl[]" class="levelChilds" id="inlineCheckbox1" <?php if (in_array($vvv, $groupAcl)):?>checked="checked"<?php endif;?>><?=$kkk;?></label>
									<?php endforeach;?>
										</div>
									</div>
									</div>
									<?php endforeach;?>
								</div>
							</div>
							<?php endforeach;?>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<button class="btn btn-primary" type="submit">保存内容</button>
									<a class="btn btn-white" href="/admin/group/index">取消</a>
									<!--<button class="btn btn-white" type="submit" onclick="window.location.href='/admin/group/index'">取消</button>-->
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
		</div>
	</div>
	<!--右侧部分结束-->
</div>
<script src="/static/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/static/js/plugins/peity/jquery.peity.min.js"></script>
<script src="/static/js/plugins/iCheck/icheck.min.js"></script>
<script type="text/javascript">
	jQuery(document).ready(function(){
		var levelFirst=jQuery('.levelFirst'),
			levelSecond=jQuery('.levelSecond'),
			levelChilds=jQuery('.levelChilds'),
			secMenu=jQuery('.secMenu')
			;
		levelFirst.click(function(){
			//判断模块的选中状态  如果选中  二级模块以及子模块全部选中
            var partInputs=jQuery(this).parent().parent().find('input');
			var levelFirstChecked=jQuery(this).prop('checked');
			partInputs.each(function(){
				jQuery(this).prop('checked',levelFirstChecked);
			});
		});
		secMenu.click(function(){
            var levelSecondCheckd=jQuery(this).prop('checked');
			var chInputs=jQuery(this).closest('div').find('input');
			var topNode=jQuery(this).closest('div').parent();//顶级节点
			chInputs.each(function(){
				jQuery(this).prop('checked',levelSecondCheckd);
			});
			checkLevelTop(topNode);
		});
		levelChilds.click(function(){
             var secondDivNode=jQuery(this).closest('div');
			 var topNode=secondDivNode.parent();
			 var count=secondDivNode.find('input[class=levelChilds]:checked').length;
			 var tmpStatus="";
			 if(count==0){
				 tmpStatus=false;
			 }else{
				 tmpStatus=true;
			 }
			secondDivNode.find('input[class=secMenu]').prop('checked',tmpStatus);
			checkLevelTop(topNode);
		});
	});
	function checkLevelTop(topNode){
		var checkedCount=topNode.find('input[class=secMenu]:checked').length;
		var parentInput=topNode.find('input[class=levelFirst]');//一级节点
		if(checkedCount==0){
			//判断顶级父节点
			parentInput.prop('checked',false);
		}else{
			parentInput.prop('checked',true);
		}
	}
</script>
